/**
 * @param {number} dividend
 * @param {number} divisor
 * @return {number}
 */
var divide = function (dividend, divisor) {
  let res, count = 0, flag = true,

    max = Math.pow(2, 31) - 1, min = Math.pow(-2, 31)
  if (dividend > max) dividend = max
  if (dividend < min) dividend = min
  if ((dividend > 0 && divisor < 0) || (dividend < 0 && divisor > 0)) {
    flag = false
  }

  dividend = Math.abs(dividend)
  divisor = Math.abs(divisor)
  res = dividend
  while (res >= divisor) {
    res = dividend - divisor
    dividend = res
    count++
  }
  console.log(1);
  // if (count > max) count = max
  // if (count < min) count = min
  return flag ? count : -count
};

divide(-2147483648, 1)